package itqf.dao;


import itqf.dao.impl.GoodTypeDao;
import itqf.entity.GoodTypes;
import itqf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * com.itqf.dao
 * 2020/9/15
 */
public class GoodTypeDaoImpl implements GoodTypeDao {
    QueryRunner qr = new QueryRunner(DruidUtils.getDateSource());
    @Override
    public List<GoodTypes> findAllTypes() {
        String sql = "select t_id as tid,t_name as tname,t_info as tinfo from `type`";
        try {
            List<GoodTypes> list = qr.query(sql, new BeanListHandler<>(GoodTypes.class));
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int insertGoodsType(String tname) {
        String sql = "insert into type(t_name)values(?)";
        try {
            return qr.update(sql,tname);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
